package org.vectrics.recruiter.struts;

import javax.servlet.jsp.JspException;

import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import org.vectrics.user.Person;

/**
 * Action que realiza una accion dependiendo de si un usuario tiene o no
 * permisos para ingresar al sistema.
 * 
 * @author ncortinez
 * 
 */
public class SubmitCredentialsAction extends VectricsStrutsAction {

    private static final String VIEW_EMPLOYEES_URI = "/hrs-intranet/admin/employee/index";

    public String doExecute(VectricsActionData actionData) throws JspException {

        Boolean userHasAccess = (Boolean) actionData.getRequest().getSession().getAttribute("userHasAccess");

        if (userHasAccess) {
            Person authPerson = CoreServiceLocator.getUserAuthService().getAuthorizedPerson(
                    actionData.getRequest().getSession());

            if (CoreServiceLocator.getUserAuthService().doesUserHavePagePrivilege(VIEW_EMPLOYEES_URI, authPerson)) {
            	return "success";
            } else if (CoreServiceLocator.getUserAuthService().doesUserHavePagePrivilege("/hrs-intranet/hrs2/ManageFeedbacksAction_initFilters", authPerson)) {
            	return "giveFeedback";
            }else if (CoreServiceLocator.getUserAuthService().doesUserHavePagePrivilege("/hrs-intranet/hrs2/MentoringAction_list", authPerson)){
            	return "mentoringRelationships";
            }
            
            return "noPermissionDefaultPage";
            
        } else {
            actionData.getRequest().getSession().setAttribute("accessError", true);
            return "failure";
        }

    }

}
